package cn.mw.cmdb.entity;

import cn.mw.cmdb.processor.MonitorGroupInfo;
import cn.mw.cmdb.service.ServiceChoose;
import cn.mw.cmdb.service.impl.ModelGroupServiceImpl;
import cn.mw.cmdb.util.DataCreateInfo;
import cn.mw.components.mongodb.anno.AutoId;
import cn.mw.components.mongodb.anno.CMDBProperty;
import cn.mw.microMonitorCommon.api.cmdb.TreeView;
import cn.mw.microMonitorCommon.api.cmdb.TreeViewType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Data
@Document("mw_cmdbmd_group")
public class ModelGroupInfo extends DataAuth implements ServiceChoose, TreeView, DataCreateInfo {

    @Schema(description = "分组id")
    @AutoId
    @CMDBProperty(searchType=PropertyTypeString.ID,searchPrefix = "_")
    private String id;

    @Schema(description = "分组名称")
    @CMDBProperty(searchType = PropertyTypeString.ID, keywordSearch = true)
    private String name;

    @Schema(description = "分组图标")
    @CMDBProperty
    private String icon;

    @Schema(description = "是否展示")
    @CMDBProperty(searchType = PropertyTypeSwitch.ID)
    private Boolean visible;

    @Schema(description = "试图类型 list:默认列表 videoOverview:视频概览")
    @CMDBProperty
    private String viewType = "list";

    @Schema(description = "父分组id")
    @CMDBProperty(searchType = PropertyTypeString.ID, keywordSearch = true)
    private List<String> path;

    @CMDBProperty(logicDel = true)
    protected Boolean delFlag = false;

    @CMDBProperty(searchType = PropertyTypeString.ID,keywordSearch = true)
    @Schema(description = "创建人")
    protected Long creater;

    @CMDBProperty(searchType = PropertyTypeTime.ID)
    @Schema(description = "创建时间")
    protected Date createTime;

    @CMDBProperty(searchType = PropertyTypeString.ID,keywordSearch = true)
    @Schema(description = "修改人")
    protected Long modifier;

    @CMDBProperty(searchType = PropertyTypeTime.ID)
    @Schema(description = "修改时间")
    protected Date modificationTime;

    @CMDBProperty
    private Map<String, Object> relatedInfo;

    //可能在不同的监控服务器类型上,如zabbix, prometheus都有对应分组id
    //因此需要是list类型
    @CMDBProperty
    private List<MonitorGroupInfo> monitorGroupInfos;

    private int count;
    @CMDBProperty
    private Integer sortNum;

    private String itemAssetsStatus;

    private List<String> childStatus;

    @Override
    public String getServiceId() {
        return ModelGroupServiceImpl.ID;
    }

    @Override
    public Object getParentId() {
        if (null != path && path.size() > 0) {
            return path.get(path.size() - 1);
        }
        return null;
    }

    @Override
    public String getItemName() {
        return getName();
    }

    @Override
    public String getType() {
        return TreeViewType.group.name();
    }

    @Override
    public Integer getSortNum() {
        return this.sortNum;
    }


    @Override
    public List<String> getChildStatus() {
        return this.childStatus;
    }

    @Override
    public void setChildStatus(List<String> status) {
        this.childStatus = status;
    }
}
